package com.xxl.job.admin.api.service.impl;

import com.xxl.job.admin.api.model.XxlJobApiApp;
import com.xxl.job.admin.api.service.XxlJobApiAppService;
import com.xxl.job.admin.dao.XxlJobApiAppDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class XxlJobApiAppServiceImpl implements XxlJobApiAppService {

    @Autowired
    private XxlJobApiAppDao xxlJobApiAppDao;

    @Override
    public List<XxlJobApiApp> findAll() {
        return xxlJobApiAppDao.findAll();
    }

    @Override
    public XxlJobApiApp findByAppId(String appId) {
        return xxlJobApiAppDao.findByAppId(appId);
    }

    @Override
    public int save(XxlJobApiApp xxlJobApiApp) {
        xxlJobApiApp.setUpdateTime(new Date());
        xxlJobApiApp.setCreateTime(new Date());
        xxlJobApiApp.setVersion(1);
        return xxlJobApiAppDao.save(xxlJobApiApp);
    }

    @Override
    public int update(XxlJobApiApp xxlJobApiApp) {
        xxlJobApiApp.setUpdateTime(new Date());
        return xxlJobApiAppDao.update(xxlJobApiApp);
    }

    @Override
    public int remove(int id) {
        return xxlJobApiAppDao.remove(id);
    }

    @Override
    public List<XxlJobApiApp> pageList(int offset, int pagesize, String appname) {
        return xxlJobApiAppDao.pageList(offset, pagesize, appname);
    }

    @Override
    public int pageListCount(int offset, int pagesize, String appname) {
        return xxlJobApiAppDao.pageListCount(offset, pagesize, appname);
    }
}
